package com.orhanobut.secrity;

import android.content.Context;

import com.orhanobut.MyLog;

import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class CrcDex {
    public static void crc(Context context, String crc){
        String apkPath = context.getPackageCodePath();
        //建议将dexCrc值放在服务器做校验
        try {
            long dexCrc = Long.parseLong(SecretUtil.decodeBase64AndDecryptAES(crc));
            ZipFile zipfile = new ZipFile(apkPath);
            ZipEntry dexentry = zipfile.getEntry("classes.dex");
            MyLog.i("verification>>>"+"classes.dexcrc="+dexentry.getCrc());
            if(dexentry.getCrc() != dexCrc){
                MyLog.i("verification>>>>"+"Dexhas been modified!");
                System.exit(0);
            }else{
                MyLog.i("verification>>>>"+"Dex hasn't been modified!");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
